package edu.pku.hawk.controller.util;

public class SendSample {

	public static void main(String[] args) {
		SendSample ss = new SendSample();
//		ss.send();
		//ss.se();
//		ss.re();
		
		ss.send_proc();
	}

	private MQManager mgr;

	public SendSample() {

		Config.Singleton.Instance.initialize();
		try {
			mgr = new MQManager(Constants.MQServer_Name, Constants.MQServer_Password, Constants.MQServer_URL);
			mgr.createProducerQueue(Constants.Ctrl_Cloud_RscRequest_QueueName);
			mgr.createProducerQueue(Constants.Ctrl_Cloud_RscRequest_QueueName);
		} catch (Exception ex) {
			ex.printStackTrace();
		}

	}

	public void send() {

		
		SerResourceList srl = new SerResourceList();
		SerResource sr = new SerResource();
		sr.setCpu(22);
		sr.setDisk(9.1);
		sr.setMem(3.3);
		sr.setNet(0.3);
		sr.setServiceID(1);
		srl.ResourceList.add(sr);

		try {
			MProducerQueue queue = mgr.getProducerQueue(Constants.Ctrl_Cloud_RscRequest_QueueName);
			queue.send(srl);
		
			MConsumerQueue q = mgr.getConsumerQueue(Constants.Ctrl_Cloud_RscResponse_QueueName);
			SerResourceList rsp = (SerResourceList)q.getObject();
		
			System.out.print(rsp.ResourceList.size());
			System.out.println(rsp.ResourceList.get(0).getServerURI());
			
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
	
	public void send1() {

		ProcDes procDes = new ProcDes();
		procDes.isConbine = true;
		procDes.detectorTypes = new int[] { Constants.TYPE_INFRARED_SENSOR, Constants.TYPE_METAL_SENSOR,
				Constants.TYPE_PRESSURE_SENSOR };

		try {
			MProducerQueue queue = mgr.getProducerQueue(Constants.Ctrl_UI_Proc_QueueName);
			queue.send(procDes);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
	
	public void send_proc() {

		ProcDes procDes = new ProcDes();
		procDes.scenarioName = "asfasd";
		procDes.isConbine = true;
//		procDes.detectorTypes = new int[] { Constants.TYPE_INFRARED_SENSOR, Constants.TYPE_METAL_SENSOR,
//				Constants.TYPE_PRESSURE_SENSOR };
//		procDes.detectorTypes = new int[] { Constants.TYPE_INFRARED_SENSOR, Constants.TYPE_METAL_SENSOR,
//				Constants.TYPE_PRESSURE_SENSOR , Constants.TYPE_TRACK };
		procDes.detectorTypes = new int[] { Constants.TYPE_INFRARED_SENSOR, Constants.TYPE_METAL_SENSOR , Constants.TYPE_TRACK };
//		procDes.detectorTypes = new int[] { Constants.TYPE_INFRARED_SENSOR, Constants.TYPE_METAL_SENSOR,
//				Constants.TYPE_RFID_SENSOR , Constants.TYPE_TRACK};

		try {
			MProducerQueue queue = mgr.getProducerQueue(Constants.Ctrl_UI_Proc_QueueName);
			queue.send(procDes);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	public void se() {


		SerResourceList r = new SerResourceList();
		try {
			MProducerQueue queue = mgr.getProducerQueue(Constants.Ctrl_Cloud_RscResponse_QueueName);
			queue.send(r);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
	
	public void re() {
		try {
			MConsumerQueue cq = mgr.getConsumerQueue(Constants.Ctrl_Cloud_RscResponse_QueueName);
			Object o = cq.getObjectNoWait();
			
			System.out.println(o);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

}
